<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <title>ClassList属性</title>
    <style>
      li {
        list-style-type: none;
        position: relative;
        margin: 2px;
        padding: 0.5em 0.5em 0.5em 2em;
        background-color: lightgray;
        font-family: sans-serif;
      }

      li.done {
        background-color: #ccff99;
      }

      /* 这里画的是✓用边框去边构成的 */
      li.done::before {
        content: "";
        position: absolute;
        border-color: #009933;
        border-style: solid;
        border-width: 0 0.3em 0.25em 0;
        height: 1em;
        top: 1.3em;
        left: 0.6em;
        margin-top: -1em;
        transform: rotate(45deg);
        width: 0.5em;
      }
    </style>
  </head>
  <body>
    <ul>
      <li>Buy milk</li>
      <li>Take the <del>dog</del> for a walk</li>
      <li>Exercise</li>
      <li>Write code</li>
      <li>Play music</li>
      <li>Relax</li>
    </ul>

    <script>
      const lists = document.querySelector("ul");
      lists.addEventListener("click", function (ev) {
        console.dir(ev.target);
        if (ev.target.tagName.toLocaleLowerCase() === "li") {
          ev.target.classList.toggle("done");
        }
      });
    </script>
  </body>
</html>
